﻿using System.Linq;
using System.Web.Mvc;
using Omu.Awesome.Mvc;
using Omu.AwesomeDemo.Core.Model;
using Omu.AwesomeDemo.Core.Repository;
using DemoExtensions = Omu.AwesomeDemo.WebUI.Controllers.DemoExtensions;

namespace Omu.AwesomeDemo.WebUI.Areas.Veggies.Controllers
{
    public class FruitLookupController : LookupController
    {
        private readonly IRepo<Fruit> repo;

        public FruitLookupController(IRepo<Fruit> repo)
        {
            this.repo = repo;
        }

        public ActionResult Search(string search)
        {
            return View(@"Awesome\LookupList", repo.GetAll().Where(o => DemoExtensions.Containz(o.Name, search)));
        }

        public ActionResult Get(int id)
        {
            return Content((repo.Get(id) ?? new Fruit()).Name);
        }
    }
}